[org 0x7c00]
KERNEL_OFFSET EQU 0x1000

PMBR_ADDRESS_START_HIGH EQU 0x0000
PMBR_ADDRESS_START_LOW EQU 0x7e00
PMBR_ADDRESS_START EQU 0xb7c6


; mov bp, 0x9000
; mov sp, bp

; call clearScreen

mov bx, MSG_PMBR_BOOT
call print_str
call print_nl

call load_pmbr

; MOV BX, MSG_LOAD_PMBR_SUCCESSFULLY
; call print_str
; call print_nl

; jmp PMBR_ADDRESS_START_HIGH:PMBR_ADDRESS_START_LOW
jmp PMBR_ADDRESS_START
; call _start
; jmp PMBR_ADDRESS_START_HIGH:PMBR_ADDRESS_START_LOW

jmp 0x7c00

MOV BX, MSG_JMP_PMBR_ERROR
call print_str
call print_nl

jmp $


; include must bello the hang
%include "../lib/real_mode/asm/print.asm" 
%include "../lib/real_mode/asm/disk_load.asm"

load_mbr:


load_pmbr:
    pusha

    mov bx, MSG_LOAD_PMBR
    call print_str
    call print_nl

    ;Buffer Address Pointer ES:BX
    mov bx, PMBR_ADDRESS_START_HIGH
    mov es, bx
    mov bx, PMBR_ADDRESS_START_LOW ; load pmbr code into PMBR_ADDRESS_START_HIGH:PMBR_ADDRESS_START_LOW
    mov dh, 64 ; load 5 sectors,通过dh传参
    call disk_load

    popa
    ret

MSG_JMP_PMBR_ERROR:
    db "Jmp PMBR ERROR", 0

MSG_LOAD_PMBR_SUCCESSFULLY:
    db "Load PMBR Success", 0

MSG_LOAD_PMBR:
    db "load PMBR", 0

MSG_PMBR_BOOT:
    db "PMBR booting...", 0

times  510-($-$$) db 0 

db 0x55,0xaa ; 这行的指令的意思是在511和512字节分别填入0x55，0xaa。这是BIOS对bootloader的要求，即512字节的最后两个字节必须是这两个数，以确实是有效的bootloader。
